import i18n from '@/lang' // i18nText
// translate router.meta.title, be used in breadcrumb sidebar tagsview
export function generateTitle(title) {
  const hasKey = this.$te('route.' + title)

  if (hasKey) {
    // $t :this method from vue-i18n, inject in @/lang/index.js
    const translatedTitle = this.$t('route.' + title)

    return translatedTitle
  }
  return title
}

/**
 * key 不存在返回默认值
 * @param {*} key
 * @param {*} defualtText
 * @returns
 */
export function i18nText(key, defualtText) {
  if (key) {
    const hasKey = i18n.te(key)
    if (hasKey) {
      return i18n.t(key)
    }
    if (defualtText) {
      return defualtText
    }
    return key
  }
  return defualtText
}

export function getLanguage() {
  return i18n.locale
}
